package com.anyou.mall.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.anyou.common.exception.GlobalException;

import java.util.Collection;

/**
 * null值校验工具
 * 断言
 */
public class AssertUtils {
    private AssertUtils() {
    }

    public static void isTrue(boolean param, String message) {
        if (param) {
            throw GlobalException.byMsg(message, new Object[0]);
        }
    }

    public static void isFalse(boolean param, String message) {
        if (!param) {
            throw GlobalException.byMsg(message, new Object[0]);
        }
    }

    public static void isNull(Object obj, String message) {
        if (ObjectUtil.isEmpty(obj)) {
            throw GlobalException.byMsg(message, new Object[0]);
        }
    }


    public static void isEmpty(Collection<?> collection, String message) {
        if (CollUtil.isEmpty(collection)) {
            throw GlobalException.byMsg(message, new Object[0]);
        }
    }

    public static void isBlank(String str, String message) {
        if (CharSequenceUtil.isBlank(str)) {
            throw GlobalException.byMsg(message, new Object[0]);
        }
    }
}
